<!--
 * @Author: your name
 * @Date: 2020-05-27 14:44:07
 * @LastEditTime: 2020-06-04 15:54:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \mobile_project_200106\mobile_project\src\pages\details\components\toShopcar.vue
--> 
<template>
  <div>
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" />
      <router-link to="/shopcar">
        <van-goods-action-icon icon="cart-o" text="购物车" :badge="getBadge" />
      </router-link>
      <van-goods-action-button type="warning" text="加入购物车" @click="showSku" />
      <van-goods-action-button type="danger" text="立即购买" @click="showSku" />
    </van-goods-action>
  </div>
</template>

<script>
import { createNamespacedHelpers } from 'vuex'
const { mapGetters } = createNamespacedHelpers('badgeModule')
export default {
  data() {
    return {
      // goodsList: JSON.parse(localStorage.getItem("goodsList")) || [], //本地缓存获取加入购物车商品数据
      // badge: 0
    };
  },

  computed:{
    ...mapGetters(["getBadge"])
  },
  // watch:{
  //     goodsList:{//实时监听徽标改变
  //         handler(newVal){
  //             this.badge=this.getBadge(newVal)   
  //         },
  //         immediate:true
  //     }
      
  // },
  methods: {
    
    showSku() {
      this.$emit("showSku");
    },
    // getBadge(list) {//获取显示的徽标
    //   let sum = 0;
    //   list.forEach(item => {
    //     sum += item.num;
    //   });
    //   return sum;
    // }
  },
  created() {
      // this.$eventBus.$on("getGoodsList",(res)=>{//获取sku的商品信息
      //     this.badge=this.getBadge(res)//赋值徽标
      // })
  }
};
</script>

<style>
</style>